<?php

/*
 * @copyright        [YouNet_COPYRIGHT]
 * @author           YouNet Company
 * @package          Module_Contactimporter
 * @version          2.06
 *
 */
defined('PHPFOX') or exit('NO DICE!');
if (file_exists(PHPFOX_DIR . 'module' . PHPFOX_DS . 'contactimporter' . PHPFOX_DS . 'include' . PHPFOX_DS . 'component' . PHPFOX_DS . 'controller' . PHPFOX_DS . 'openinviter' . PHPFOX_DS . 'openinviter.php')) {
    require_once(PHPFOX_DIR . 'module' . PHPFOX_DS . 'contactimporter' . PHPFOX_DS . 'include' . PHPFOX_DS . 'component' . PHPFOX_DS . 'controller' . PHPFOX_DS . 'openinviter' . PHPFOX_DS . 'openinviter.php');
}
?>
<?php

class Contactimporter_Component_Controller_Index extends Phpfox_Component {

    public function process() {
        Phpfox_Error::skip(true);
        $sProvider = $this->request()->get('req2');

        $sCurUrl = $_SERVER['REQUEST_URI'];
        $sCurUrl = str_replace('/index.php?do=', '', $sCurUrl);
        parse_str($sCurUrl, $aParams);
        $bIsLinkedIn = false;
        foreach ($aParams as $key => $val) {
            if (strpos($key, 'contact') !== false && $val == 'mycontact') {
                $bIsLinkedIn = true;
                break;
            }
            if (strpos($key, '?session') !== false) {
                $bIsFacebook = true;
                $session = json_decode($val);
                $oFacebook = Phpfox::getService('contactimporter.facebook');
                $oFacebook->setSession($session);
                break;
            }
        }

        if ($bIsLinkedIn) {
            $_SESSION['token'] = $aParams['oauth_tok3n'];
            $_SESSION['secret_token'] = $aParams['oauth_token_secret'];
            $this->url()->send('contactimporter.linkedin');
            exit;
        }

        if ($bIsFacebook) {
            $this->url()->send('contactimporter.facebook');
            exit;
        }
        //$aEmailProviders = array('yahoo', 'gmail', 'hotmail', 'techemail', 'famiva', 'fdcareer', 'kincafe', 'hyves', 'motortopia', 'netlog', 'perfspot', 'plurk');

        $aEmailProviders = array('yahoo', 'gmail', 'hotmail');
        if (in_array($sProvider, $aEmailProviders)) {
            return Phpfox::getLib('module')->setController('contactimporter.email');
        }
        if ($sProvider == 'facebook' || $sProvider == 'twitter' || $sProvider == 'linkedin') {
            return Phpfox::getLib('module')->setController('contactimporter.social');
        }

        foreach ($aEmailProviders as $sProviderName) {
            if (isset($_SESSION['contactimporter'][$sProviderName])) {
                unset($_SESSION['contactimporter'][$sProviderName]);
            }
            if (isset($_SESSION['contactimporter'][$sProviderName . '_invite_list'])) {
                unset($_SESSION['contactimporter'][$sProviderName . '_invite_list']);
            }
        }

        if (!Phpfox::isUser()) {
            $this->url()->send('login', null, Phpfox::getPhrase('contactimporter.need_to_be_logged_in_for_getting_the_contact_importer_feature'));
        }
        $this->template()->assign(array(
            'sSecurityToken' => Phpfox::getService('log.session')->getToken(),
            'contactimporter_link' => phpfox::getLib('url')->makeUrl('contactimporter'),
            'homepage' => phpfox::getParam('core.path'),
        ));

        $max_invitation = Phpfox::getService('contactimporter')->getMaxInvitation();
        $this->setParam('max_invitation', $max_invitation);
        $this->template()->assign(array('max_invitation' => $max_invitation));
        $aHotmailContacts = isset($_REQUEST['hotmail_contact']) ? json_decode(stripslashes($_REQUEST['hotmail_contact'])) : null;
        if ($aHotmailContacts) {
            $aHotmail = Phpfox::getService('contactimporter')->getContactsHotmail($aHotmailContacts);
            if (!empty($aHotmail[0])) {
                $errors = '';
                $step = "get_invite";
                $this->template()->assign(array(
                    'step' => $step,
                    'invite_list_sorts' => $aHotmail[0],
                    'aValid' => $aHotmail[1],
                    'errors' => $errors,
                    'aInValid' => $aHotmail[2],
                    'aUsers' => $aHotmail[3],
                    'plugType' => 'email',
                    'provider_box' => 'hotmail',
                    'tokenName' => Phpfox::getTokenName(),
                    'tokenPhpFoxValue' => Phpfox::getService('log.session')->getToken(),
                    'oi_session_id' => uniqid(),
                    'core_url' => phpfox::getParam('core.path'),
                    'sIniviteLink' => Phpfox::getLib('url')->makeUrl('contactimporter.inviteuser', array('id' => Phpfox::getUserId())),
                ));
                $this->template()->setHeader(array(
                    'jquery.scrollTo-min.js' => 'module_contactimporter',
                    'jquery.localscroll-min.js' => 'module_contactimporter',
                    'init.js' => 'module_contactimporter',
                ));
                return;
            } else {
                $this->url()->send('contactimporter.invitations', null, Phpfox::getPhrase('invite.your_friends_have_successfully_been_invited'));
            }
        } elseif (isset($_REQUEST['get_success']) && $_REQUEST['get_success'] == 1) {
            $errors['contacts'] = Phpfox::getPhrase('contactimporter.there_is_not_contact_in_your_account');
            $this->template()->assign(array('plugType' => 'email', 'provider_type' => 'hotmail', 'errors' => $errors));
        }

        $sGetContact = $this->request()->get('req2');

        $aYahooContacts = isset($_REQUEST['contact']) ? json_decode(urldecode($_REQUEST['contact'])) : null;
        if (isset($aYahooContacts[0]->errors) != '') {
            $errors['contacts'] = $aYahooContacts[0]->errors;
            $this->template()->assign(array('plugType' => 'email', 'provider_type' => 'yahoo', 'errors' => $errors));
        } else {
            $aYahoo = Phpfox::getService('contactimporter')->getContactsYahoo($aYahooContacts);
            if (!empty($aYahoo[0])) {
                $errors = '';
                $step = "get_invite";
                $this->template()->assign(array(
                    'step' => $step,
                    'invite_list_sorts' => $aYahoo[0],
                    'aValid' => $aYahoo[1],
                    'errors' => $errors,
                    'aInValid' => $aYahoo[2],
                    'aUsers' => $aYahoo[3],
                    'plugType' => 'email',
                    'provider_box' => 'yahoo',
                    'tokenName' => Phpfox::getTokenName(),
                    'tokenPhpFoxValue' => Phpfox::getService('log.session')->getToken(),
                    'oi_session_id' => '9299392939293',
                    'core_url' => phpfox::getParam('core.path'),
                    'sIniviteLink' => Phpfox::getLib('url')->makeUrl('contactimporter.inviteuser', array('id' => Phpfox::getUserId())),
                ));
                $this->template()->setHeader(array(
                    'importer.css' => 'module_contactimporter',
                    'jquery.autocomplete.js' => 'module_contactimporter',
                    'jquery.autocomplete.css' => 'module_contactimporter',
                    'jquery.scrollTo-min.js' => 'module_contactimporter',
                    'jquery.localscroll-min.js' => 'module_contactimporter',
                    'init.js' => 'module_contactimporter',
                ));
                return;
            }
        }

        /** Twitter * */
        $twconnect = $this->request()->get('req2');
        if ($twconnect == 'twcontact') {
            $errors = '';
            require_once(PHPFOX_DIR . 'module' . PHPFOX_DS . 'contactimporter' . PHPFOX_DS . 'include' . PHPFOX_DS . 'component' . PHPFOX_DS . 'controller' . PHPFOX_DS . 'Apiconnection' . PHPFOX_DS . 'twitter.php');
            $step = 'add_contact';
            $sCursor = $this->request()->get('cursor', -1);
            $iPage = $this->request()->get('page', 1);
            $iLimit = 100;
            $iOffset = ($iPage - 1) * $iLimit;
            $iCnt = $_SESSION['twitter']['followers_count'];
            $aSetting = Phpfox::getService('contactimporter.setting')->getApiSetting('twitter');
            $aSetting['api_params'] = unserialize($aSetting['api_params']);
            $oTwitter = new Twitter($aSetting['api_params']['appid'], $aSetting['api_params']['secret']);
            $oTwitter->setOAuthToken($_SESSION['twitter']['oauth_token']);
            $oTwitter->setOAuthTokenSecret($_SESSION['twitter']['oauth_token_secret']);
            list($next, $friend_ids) = $oTwitter->followersIds(null, $_SESSION['twitter']['user_id'], null, $sCursor);
            if ($friend_ids) {
                $friend_ids = array_slice($friend_ids, $iOffset, $iLimit);
            }
            $sLinkNext = $sLinkPrev = '';
            if (!isset($_SESSION['twitter']['page'])) {
                $_SESSION['twitter']['page'] = array();
            }
            if ($next) {
                $_SESSION['twitter']['page'][] = Phpfox::getLib('url')->makeUrl('contactimporter.twcontact', array('cursor' => $next));
            }
            $aTwPage = $_SESSION['twitter']['page'];
            if (count($aTwPage) > 0) {
                $iPageCnt = count($aTwPage);
                $sLinkNext = $aTwPage[$iPageCnt - 1];
                if ($iPageCnt > 1 && isset($aTwPage[$iPageCnt - 2])) {
                    $sLinkPrev = $aTwPage[$iPageCnt - 2];
                }
            }
            $contacts = $oTwitter->usersLookup($friend_ids, null);
            foreach ($contacts as $key => $email) {
                $email['pic'] = $email['profile_image_url'];
                $char = strtoupper(substr($email['name'], 0, 1));
                $social_c = ord($char);
                for ($start = ord('A'); $start <= ord('Z'); $start++) {
                    if ($social_c == $start) {
                        if (is_array($email)) {
                            $contact_list[chr($start)][] = array('key' => $email['id'], 'name' => $email['name'], 'pic' => $email['pic'], 'screen_name' => $email['screen_name']);
                            break;
                        } else {
                            $contact_list[chr($start)][] = array('key' => $email['id'], 'name' => $email, 'pic' => '', 'screen_name' => $email['screen_name']);
                            break;
                        }
                    } else {
                        if (!isset($contact_list[chr($start)]))
                            $contact_list[chr($start)] = array();
                    }
                }
            }
            for ($start = ord('A'); $start <= ord('Z'); $start++) {
                if (!isset($contact_list[chr($start)]))
                    $contact_list[chr($start)] = array();
            }

            $this->template()->assign(array(
                        'sLinkPrev' => $sLinkPrev,
                        'sLinkNext' => $sLinkNext,
                        'step' => $step,
                        'errors' => $errors,
                        'plugType' => 'social',
                        'oi_session_id ' => '',
                        'social_invite_list' => $contact_list,
                        'friends_count' => $iCnt,
                        'provider_box' => 'twitter',
                        'sIniviteLink' => Phpfox::getLib('url')->makeUrl('contactimporter.inviteuser', array('id' => Phpfox::getUserId())),
                        'core_url' => phpfox::getParam('core.path')
                            )
                    )
//                    ->setBreadcrumb(Phpfox::getPhrase('contactimporter.breadcrumb_contactimporter_title'))
                    ->setHeader(array(
                        'importer.css' => 'module_contactimporter',
                        'jquery.autocomplete.js' => 'module_contactimporter',
                        'jquery.autocomplete.css' => 'module_contactimporter',
                        'jquery.scrollTo-min.js' => 'module_contactimporter',
                        'jquery.localscroll-min.js' => 'module_contactimporter',
                        'init.js' => 'module_contactimporter',
                        'slide.js' => 'module_contactimporter',
                    ));
            Phpfox::getLib('pager')->set(array('page' => $iPage, 'size' => $iLimit, 'count' => $iCnt));
            return;
        }
        /** End Twitter * */
        /** Facebook * */
        $fb_f_c = Phpfox::getService('contactimporter');
        $oFacebook = $fb_f_c->initFB();
        if ($oFacebook == false) {
            //Phpfox_Error::set(Phpfox::getPhrase('contactimporter.please_enter_your_facebook_api'));
            if (Phpfox::getParam('core.site_wide_ajax_browsing') == true) {
                Phpfox_Error::setDisplay(false);
            }
        }
        $_SESSION['contact_url'] = Phpfox::getLib('url')->makeUrl('contactimporter');
        $fbconnect = $this->request()->get('req2');
        if ($fb_f_c->verifyFB() && ($fbconnect == "fbcontact")) {
            $me = null;
            $me = @$fb_f_c->getUserProfileFB();
            if ($me == null) {
                $loginUrl = $fb_f_c->getLoginUrl();
                $this->template()->assign(array(
                    'fbloginUrl' => $loginUrl
                ));
            } else {
                $iPage = $this->request()->get('page', 1);
                $iLimit = 100;
                $iCnt = $me['friend_count'];
                $step = 'add_contact';
                $contacts = $fb_f_c->getUserFriendsFB($iPage, $iLimit);
                foreach ($contacts as $key => $email) {
                    if (!is_numeric($key))
                        continue;
                    $char = strtoupper(substr($email['name'], 0, 1));
                    $social_c = ord($char);
                    for ($start = ord('A'); $start <= ord('Z'); $start++) {
                        if ($social_c == $start) {
                            if (is_array($email)) {
                                $contact_list[chr($start)][] = array('key' => $key, 'name' => $email['name'], 'pic' => $email['pic']);
                                break;
                            } else {
                                $contact_list[chr($start)][] = array('key' => $key, 'name' => $email, 'pic' => '');
                                break;
                            }
                        } else {
                            if (!isset($contact_list[chr($start)]))
                                $contact_list[chr($start)] = array();
                        }
                    }
                }
                for ($start = ord('A'); $start <= ord('Z'); $start++) {
                    if (!isset($contact_list[chr($start)]))
                        $contact_list[chr($start)] = array();
                }

                $errors = '';
                $this->template()->assign(array(
                            'step' => $step,
                            'errors' => $errors,
                            'social_invite_list' => $contact_list,
                            'friends_count' => $iCnt,
                            'provider_box' => 'facebook',
                            'sIniviteLink' => Phpfox::getLib('url')->makeUrl('contactimporter.inviteuser', array('id' => Phpfox::getUserId())),
                            'core_url' => phpfox::getParam('core.path')
                                )
                        )
//                        ->setBreadcrumb(Phpfox::getPhrase('contactimporter.breadcrumb_contactimporter_title'))
                        ->setHeader(array(
                            'importer.css' => 'module_contactimporter',
                            'jquery.autocomplete.js' => 'module_contactimporter',
                            'jquery.autocomplete.css' => 'module_contactimporter',
                            'jquery.scrollTo-min.js' => 'module_contactimporter',
                            'jquery.localscroll-min.js' => 'module_contactimporter',
                            'init.js' => 'module_contactimporter',
                            'slide.js' => 'module_contactimporter',
                        ));

                Phpfox::getLib('pager')->set(array('page' => $iPage, 'size' => $iLimit, 'count' => $iCnt));
                return;
            }
        }
        else {
            $loginUrl = $fb_f_c->getLoginUrl();
            $this->template()->assign(array(
                'fbloginUrl' => $loginUrl
            ));
        }
        /*         * END FACEBOOK* */

        $cur_url = $_SERVER['REQUEST_URI'];
        $cur_url = str_replace('/index.php?do=', '', $cur_url);
        parse_str($cur_url, $params);
        $contacts = array();
        $aInserts = array();
        $index = 0;
        $id = "";
        $name = "";
        $pic = "";
        $getcontact = false;
        $token = "";
        $secret_token = "";
        $getcontactYN = false;
        $getcontactTW = false;
        $errors = array();
        $this->template()->assign(array('sIniviteLink' => Phpfox::getLib('url')->makeUrl('contactimporter.inviteuser', array('id' => Phpfox::getUserId())),));
        $this->template()->setHeader('cache', array(
            'pager.css' => 'style_css',
        ));

        foreach ($params as $key => $val) {
            if (strpos($key, '?user') !== false) {
                $getcontactTW = true;
                $_SESSION['user_id'] = $val;
            }
            if (strpos($key, '?contact') !== false) {
                $getcontact = true;
            }
            if (strpos($key, '?token') !== false) {
                $getcontactYN = true;
                $_SESSION['token_YT'] = $val;
            }
            if (strpos($key, 'oauth_tok3n') !== false) {
                $token = $val;
                $_SESSION['token'] = $token;
            }
            if (strpos($key, 'oauth_token_secret') !== false) {
                $secret_token = $val;
                $_SESSION['secret_token'] = $secret_token;
            }

            $pic = null;
            if (strpos($key, 'id_') !== false) {
                $id = $val;
            }
            if (strpos($key, 'name_') !== false) {
                $name = $val;
            }
            if (strpos($key, 'pic_') !== false) {

                $pic = $val;
                $index = 2;
            }

            if ($index >= 2) {
                $contacts[$id] = array('id' => $id, 'name' => $name, 'pic' => $pic);
            }
        }

        if ($getcontact) {
            $_SESSION['token'] = $token;
            $_SESSION['secret_token'] = $secret_token;
            $contacts = phpfox::getService('contactimporter')->getContacts();
            if (count($contacts) > 0) {
                $contact_list = phpfox::getService('contactimporter')->displayContacts($contacts);
                $this->template()->assign(array('is_linkedAPI' => 'is_linkedAPI', 'social_invite_list' => $contact_list));
            } else {
                $errors['contacts'] = Phpfox::getPhrase('contactimporter.there_is_not_contact_in_your_account');
                $this->template()->assign(array('plugType' => 'social', 'provider_type' => 'linkedin', 'errors' => $errors));
            }
        }
        $urs = $this->request()->get('email_box');
        if (!empty($urs)) {
            $_SESSION['username'] = $this->request()->get('email_box');
        }
        if ($getcontactYN) {
            $contacts = phpfox::getService('contactimporter')->getContactsYT();
            if (count($contacts) > 0) {
                $contact_list = phpfox::getService('contactimporter')->displayContacts($contacts);
                $this->template()->assign(array(
                            'step' => isset($step) ? $step : "",
                            'social_invite_list' => $contact_list,
                            'is_and_YT' => 'is_and_YT',
                            'is_linkedAPI' => 'is_linkedAPI',
                            'sIniviteLink' => Phpfox::getLib('url')->makeUrl('contactimporter.inviteuser', array('id' => Phpfox::getUserId())),
                            'core_url' => phpfox::getParam('core.path')
                                )
                        )
//                        ->setBreadcrumb(Phpfox::getPhrase('contactimporter.contact_importer'))
                        ->setHeader(array(
                            'importer.css' => 'module_contactimporter',
                            'jquery.autocomplete.js' => 'module_contactimporter',
                            'jquery.autocomplete.css' => 'module_contactimporter',
                            'jquery.scrollTo-min.js' => 'module_contactimporter',
                            'jquery.localscroll-min.js' => 'module_contactimporter',
                            'init.js' => 'module_contactimporter',
                            'slide.js' => 'module_contactimporter',
                        ));
                return;
            } else {
                $errors['contacts'] = Phpfox::getPhrase('contactimporter.there_is_not_contact_in_your_account');
                $this->template()->assign(array('plugType' => 'social', 'provider_type' => 'youtube', 'errors' => $errors));
            }
        }

        if ($getcontactTW) {
            $_SESSION['token'] = $token;
            $_SESSION['secret_token'] = $secret_token;
            $contacts = phpfox::getService('contactimporter')->getContactsTW();
            if (count($contacts) > 0) {
                $contact_list = phpfox::getService('contactimporter')->displayContacts($contacts);
                $this->template()->assign(array('is_linkedAPI' => 'is_linkedAPI', 'social_invite_list' => $contact_list, 'provider_box' => isset($provider_box)));
                $this->template()->assign(array('is_and_YT' => 'is_and_TW'));
            } else {
                Phpfox::getPhrase('contactimporter.there_is_not_contact_in_your_account');
                $this->template()->assign(array('plugType' => 'social', 'provider_type' => 'twitter', 'errors' => $errors));
            }
        }

        $plugType = "";
        $core_url = Phpfox::getParam('core.path');
        $this->template()->assign(array('core_url' => $core_url));
        $oi_services = phpfox::getService('contactimporter')->getProvidersEnable();
        $options = $mapkey = array();
        foreach ($oi_services as $provider) {
            if ($provider['type'] == 'social') {
                $options[$provider['name']] = "{$provider['title']}";
                if ($provider['type'] == "email") {
                    $supported_domains = unserialize($provider['supported_domain']);
                    foreach ($supported_domains as $domain) {
                        $mapkey[$domain] = $provider['name'];
                    }
                    $mapkey[$provider['name']] = $provider['name'];
                }
            }
        }
        $step = 'get_contact';
        $provider_lists = Phpfox::getService('contactimporter')->getAllowProviders();

        /*
          $provider_lists = Phpfox::getLib('phpfox.database')->select('*')
          ->from(Phpfox::getT('contactimporter_providers'),'cp')
          ->where('(type = "email" AND enable = 1 AND default_domain !="" ) OR (type = "social" AND enable = 1)')
          ->order('cp.order_providers ASC')
          ->execute('getSlaveRows');

          $provider_lists = phpfox::getService('contactimporter')->allowProvider($provider_lists);
         */
        $this->template()->assign(array(
            'provider_lists' => $provider_lists,
            'step' => $step
        ));

        $list_provider_domain_name_mail = Phpfox::getLib('phpfox.database')->select('*')
                ->from(Phpfox::getT('contactimporter_providers'), 'cp')
                ->where('type = "email" AND enable = 1 AND default_domain !=" " ')
                ->order('cp.order_providers ASC')
                ->execute('getSlaveRows');
        $list_provider_domain_name_mail = phpfox::getService('contactimporter')->allowProvider($list_provider_domain_name_mail);

        $this->template()->setTitle(Phpfox::getPhrase('contactimporter.contact_importer'))
//                ->setBreadcrumb(Phpfox::getPhrase('contactimporter.contact_importer'))
                ->setHeader(array(
                    'importer.css' => 'module_contactimporter',
                    'jquery.autocomplete.js' => 'module_contactimporter',
                    'jquery.autocomplete.css' => 'module_contactimporter',
                    'jquery.scrollTo-min.js' => 'module_contactimporter',
                    'jquery.localscroll-min.js' => 'module_contactimporter',
                    'init.js' => 'module_contactimporter',
                    'slide.js' => 'module_contactimporter',
                ));

        $request = $this->request();
        $provider_box = $request->get('provider_box');
        if ($request->get('provider_box2') != '')
            $provider_box = $request->get('provider_box2');
        $provider_arr = explode('.', $provider_box);
        if (!empty($provider_arr))
            $provider_box = $provider_arr[0];
        $type_err = '';
        $plugType = '';
        $errors = array();
        $this->template()->assign(array('type_email' => $provider_box));
        $uploadcsv = $request->get('uploadcsv');
        if ($request->get('task') == 'skip') {
            return;
        }
        if (isset($uploadcsv) && $uploadcsv != null) {
            $service = Phpfox::getService('contactimporter');
            $results = $service->getContactsFromCSVFile(Phpfox::getUserId());
            if ($results['is_error'] != 0) {
                $this->template()->assign(array('uploadcsv' => 'uploadcsv', 'error_message' => $results['error_message']));
            } else {
                $step = 'get_invite';
                $contacts = $results['contacts'];
                $emailContacts = phpfox::getService('contactimporter')->displayEmailContacts($contacts);
                if (count($emailContacts[1]) > 0 || count($emailContacts[3]) > 0) {
                    $this->template()->assign(array('invite_list' => $invite_list, 'in_lst' => $in_lst, 'invite_list_sorts' => $emailContacts[0]));
                    $this->template()->assign(array(
                        'aValid' => $emailContacts[1], //$aMails,
                        'aInValid' => $emailContacts[2], //$aInvalid,
                        'aUsers' => $emailContacts[3], //$aCacheUsers,
                        'step' => $step,
                        'oi_session_id' => '9299392939293'
                            )
                    );
                } else {
                    $error_message = Phpfox::getPhrase('contactimporter.all_your_contacts_was_sent_the_invitation');
                    $this->template()->assign(array('uploadcsv' => 'uploadcsv', 'error_message' => $error_message));
                }
            }
        }
        if (isset($provider_box) && $provider_box != null) {
            foreach ($oi_services as $provider) {
                if ($provider['name'] == $provider_box) {
                    $plugType = $provider['o_type'];
                    $type_err = $provider['type'];
                    break;
                }
            }
            $this->template()->assign(array('plugType' => $plugType, 'type_err' => $type_err));
            $email_box = $request->get('email_box');
            $password_box = $request->get('password_box');
            $provider_internal = array('gmail', 'myspace', 'flickr', 'hi5', 'plaxo', 'aol', 'plurk', 'fdcareer', 'netlog', 'perfspot', 'mycatspace', 'motortopia');
            if ($provider_box == 'youtube') {
                $plugType = 'social';
                $aYouTubeContacts = phpfox::getService('contactimporter')->getContactsYT($email_box, $password_box);
                $errors = $aYouTubeContacts->error;
                $contacts = $aYouTubeContacts->contacts;
                if (!$errors) {
                    $_SESSION['YT_EMAIL'] = $email_box;
                    $_SESSION['YT_PASS'] = $password_box;
                }
            } elseif (in_array($provider_box, $provider_internal)) {
                $openinviter = null;
                if (!isset($openinviter) && $openinviter == null) {
                    $openinviter = new openinviter();
                }
                $inPlugin = $openinviter->getPlugins(true);
                $openinviter->startPlugin($provider_box, true);
                $internal = $openinviter->getInternalError();
                if ($internal != null) {
                    $errors['inviter'] = $internal;
                } elseif (!$openinviter->login($email_box, $password_box)) {
                    $internal = $openinviter->getInternalError();
                    $errors['login'] = $internal ? $internal : Phpfox::getPhrase('contactimporter.login_failed_please_check_the_email_and_password_you_have_provided_and_try_again_later');
                } elseif (false === $contacts = $openinviter->getMyContacts()) {

                    $errors['contacts'] = Phpfox::getPhrase('contactimporter.unable_to_get_contacts');
                } elseif (count($contacts) == 0) {
                    $errors['contacts'] = Phpfox::getPhrase('contactimporter.there_is_not_contact_in_your_account');
                } else {
                    $import_ok = true;
                    $oi_session_id = $openinviter->plugin->getSessionID();
                    $this->template()->assign(array('oi_session_id' => $oi_session_id, 'provider_box' => $provider_box));
                }
            } else {
                $openproviderContacts = phpfox::getService('contactimporter')->getContactOpenviter($provider_box, $email_box, $password_box);
                if ($openproviderContacts) {
                    $provider_box = $openproviderContacts->provider_box;
                    $oi_session_id = $openproviderContacts->oi_session_id;
                    $errors = $openproviderContacts->error;
                    if (is_object($openproviderContacts->contacts)) {
                        $openproviderContacts->contacts = (array) $openproviderContacts->contacts;
                    }
                    if (count($openproviderContacts->contacts) > 0 && is_array($openproviderContacts->contacts)) {
                        foreach ($openproviderContacts->contacts as $key => $aContacts) {
                            $contacts[$key] = $aContacts;
                        }
                    }
                } else {
                    $errors['login'] = Phpfox::getPhrase('contactimporter.login_failed_please_check_the_email_and_password_you_have_provided_and_try_again_later');
                }
            }

            if (isset($errors) && $errors != null) {
                $this->template()->assign(array('provider_type' => $provider_box, 'type_err' => $type_err, 'errors' => $errors));
            } else {
                if ($plugType == 'email') {
                    $step = 'get_invite';
                    $errors = '';
                    $emailContacts = phpfox::getService('contactimporter')->displayEmailContacts($contacts);
                    if (count($emailContacts[1]) > 0 || count($emailContacts[3]) > 0) {
                        $invite_list = $emailContacts;
                        $in_lst = array();
                        $this->template()->assign(array('invite_list' => $invite_list, 'in_lst' => $in_lst, 'invite_list_sorts' => $emailContacts[0]));
                        $this->template()->assign(array(
                            'aValid' => $emailContacts[1],
                            'aInValid' => $emailContacts[2],
                            'aUsers' => $emailContacts[3],
                            'step' => $step,
                            'errors' => $errors,
                            'oi_session_id' => $oi_session_id,
                            'provider_box' => $provider_box,
                        ));
                        return;
                    } else {
                        $errors['contacts'] = Phpfox::getPhrase('contactimporter.there_is_not_contact_in_your_account');
                        $this->template()->assign(array('provider_type' => $provider_box, 'plugType' => $plugType, 'type_err' => $type_err, 'errors' => $errors));
                        return;
                    }
                } elseif ($plugType == 'social') {
                    $step = 'add_contact';
                    $errors = '';
                    $contact_list = phpfox::getService('contactimporter')->displayContacts($contacts);
                    if (count($contact_list) > 0) {
                        $this->template()->assign(array('step' => $step, 'errors' => $errors, 'social_invite_list' => $contact_list, 'provider_box' => $provider_box, 'oi_session_id' => $oi_session_id));
                        return;
                    } else {
                        $errors['contacts'] = Phpfox::getPhrase('contactimporter.there_is_not_contact_in_your_account');
                        $this->template()->assign(array('provider_type' => $provider_box, 'step' => $step, 'social_invite_list' => $contact_list, 'provider_box' => $provider_box, 'oi_session_id' => $oi_session_id, 'plugType' => 'social', 'errors' => $errors));
                        return;
                    }
                }
            }
        }
        // Loading feed
        $this->template()->setHeader('cache', array(
                    'sort.js' => 'module_theme',
                    'design.js' => 'module_theme',
                    'video.css' => 'module_video'
                        )
        );
        $this->template()->setHeader('cache', array(
                    'feed.js' => 'module_feed',
                    'welcome.css' => 'style_css',
                    'announcement.css' => 'style_css',
                    'comment.css' => 'style_css',
                    'quick_edit.js' => 'static_script',
                    'jquery/plugin/jquery.highlightFade.js' => 'static_script',
                    'jquery/plugin/jquery.scrollTo.js' => 'static_script'
                        )
                )
                ->setEditor(array(
                    'load' => 'simple'
                        )
        );
    }

}

?>